// ElegirBaseServer.cpp : implementation file
//

#include "stdafx.h"
#include "isismarc.h"
#include "ElegirBaseServer.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CElegirBaseServer dialog


CElegirBaseServer::CElegirBaseServer(CWnd* pParent /*=NULL*/)
	: CDialog(CElegirBaseServer::IDD, pParent)
{
	//{{AFX_DATA_INIT(CElegirBaseServer)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CElegirBaseServer::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CElegirBaseServer)
	DDX_Control(pDX, IDC_LISTABASES, m_ListaBases);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CElegirBaseServer, CDialog)
	//{{AFX_MSG_MAP(CElegirBaseServer)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CElegirBaseServer message handlers

BOOL CElegirBaseServer::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here


	SetIcon (AfxGetApp()->LoadIcon(IDR_MAINFRAME),false);
	

	m_pImageList = new CImageList();
	ASSERT(m_pImageList != NULL);    // serious allocation failure checking
	m_pImageList->Create(16, 16, ILC_MASK,   1, 1);
	m_pImageList->Add(AfxGetApp()->LoadIcon(IDI_ICONOSERVERS));

	m_ListaBases.SetImageList(m_pImageList, LVSIL_SMALL);
	m_ListaBases.SetExtendedStyle ( LVS_EX_FULLROWSELECT );



	this->baseSeleccionada = "CANCEL";

	CArray <CString, CString>  mivector; 
	CArray <CString, CString> * vector; 

	vector = &mivector;


	this->client.returnDatabases(vector);



	m_ListaBases.InsertColumn(0,"Databases", LVCFMT_LEFT,300);
	

	for (int i=0;i<vector->GetSize();i++)
	{
		int n_Elemento = m_ListaBases.InsertItem(i,(CString)vector->GetAt(i));
		
		
		//m_ListaDestinos.SetItemData(m_ListaDestinos.GetCount()-1,);
		
	}

	m_ListaBases.SetFocus();
	//delete vector;
	
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

CString CElegirBaseServer::getBaseSeleccionada()
{
	return this->baseSeleccionada;

}

void CElegirBaseServer::OnOK() 
{
	// TODO: Add extra validation here

	CListCtrl* pListCtrl = (CListCtrl*) GetDlgItem(IDC_LISTABASES);
	ASSERT(pListCtrl != NULL);

	destino midest;


	
	POSITION pos = pListCtrl->GetFirstSelectedItemPosition();
	if (pos == NULL)
	{
			AfxMessageBox (tMensaje[46][3]);
			return;
	}
	else
	{
		int nItem = pListCtrl->GetNextSelectedItem(pos);
		this->baseSeleccionada = m_ListaBases.GetItemText(nItem,0);			
			

	}	


	CDialog::OnOK();
}
